﻿

$(document).ready(function(){
		jPagesresign("myDesignTableDIV","#myDesignTableDIVbuttom");
		$("#newProduct").dialog({
			autoOpen:false,
			height:460,
			width:320,
			overlay: {opacity: 0.5, background: "black" ,overflow:'auto'},
			title:"提交新的作品",
			position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
			resizable:false
		});
		$("#private_comm").dialog({
		autoOpen : false,
		module : true,
		hide : "fadeout",
		modal : true,
		title : "发私信",
		width:300,
		height:310,
		position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
		resizable:false
	});
	$("#jubao").dialog({
		autoOpen : false,
		module : true,
		hide : "fadeout",
		modal : true,
		title : "举报",
		width:400,
		height:200,
		position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
		resizable:false
	});
	$("#myfriendslist").dialog({
		autoOpen : false,
		module : true,
		hide : "fadeout",
		modal : true,
		title : "我的好友",
		width:370,
		height:200,
		position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
		resizable:false
	});
	$("#projectEdit").dialog({
		autoOpen : false,
		module : true,
		hide : "fadeout",
		modal : true,
		title : "设计信息",
		width:420,
		height:250,
		position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
		resizable:false
	});
	$("#shangchuanMsg").dialog({
		autoOpen : false,
		module : true,
		modal : true,
		title : "系统信息",
		width:300,
		height:100,
		position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
		resizable:false,
		closeOnEscape:false,
		open:function(){
			$(".ui-dialog-titlebar-close").hide();
		},
		close:function(){
			$(".ui-dialog-titlebar-close").show();
		}
	});
	});
	$(document).keydown(function(event){
		if(event.keyCode==13&&$(document.activeElement).attr("id")=="searchinputtext"){
			searchMyRecoFriends();
		}
	});
	$(window).load(function() {
		$(".flexslider").flexslider();
	});
	function picturemouseover(){
		$("#fangxiangdiv").fadeIn(300);
	}
	function picturemouseout(){
		$("#fangxiangdiv").fadeOut(300);
	}



function jPagesresign(id, classname) {
	$("" + classname).jPages({
		containerID : id,
		first : '首页 ',
		last : ' 尾页',
		previous : ' 上页 ',
		next : ' 下页 ',
		perPage : 2,
		startPage : 1,
		startRange : 2,
		midRange : 3,
		endRange : 2,
		animation : 'flash',// 有以下几种选择 flash bounce shake tada swing wobble
		// wiggle pulse
		keyBrowse : true,
		callback : function(pages, items) {
			items.showing.find("img").trigger("turnPage");
			items.oncoming.find("img").trigger("turnPage");
		}
	});
}
function showMyDesign(){
	document.getElementById("shoppingCar_subtitle").style.display="";
	document.getElementById("myDesignTable").style.display="";
	document.getElementById("myOrderTable").style.display="none";
	document.getElementById("MyProjectTable").style.display="none";
}
function myDesign(){
	document.getElementById("shoppingCar_subtitle").style.display="";
	document.getElementById("myDesignTable").style.display="";
	document.getElementById("myOrderTable").style.display="none";
	document.getElementById("MyProjectTable").style.display="none";
	document.getElementById("friend_content_right").style.display="none";
	document.getElementById("shareContent").style.display="none";
}
function showMyProject(){
	//判断用户是否是设计师
	$.getJSON("checkUserIsDesigner.action",{d:new Date().getTime()},function(data){
		if(data.i==0){
			if(confirm("您不是设计师，转动到注册设计师页面吗?")){
				window.location.href="/register.jsp";
			}
		}else{
		$.getJSON("ShowMyProduct.action",{
			d:new Date().getTime()
		},function(data){
			var pro=document.getElementById("MyProjectTable");
			$("#MyProjectTable").empty();
			$("#MyProjectTable").append("<input type='button' id='uploadNewProduct' value='提交新的作品' onclick='$(\"#newProduct\").dialog(\"open\");' style='float:left;font-size:30px;margin-top:25px;'>");
			var indexx=1;
			$.each(data.plist,function(index,v){
				var out=document.createElement("div");
				out.setAttribute("style", "font-family:'微软雅黑';padding-top: 10px; overflow: hidden; width: 600px; clear: both; display: block; opacity: 1;");
				pro.appendChild(out);
				var table=document.createElement("table");
				table.setAttribute("style", "float:left;");
				out.appendChild(table);
				var tr=document.createElement("tr");
				var tr2=document.createElement("tr");
				var tr3=document.createElement("tr");
				var tr1=document.createElement("tr");
				var tr4=document.createElement("tr");
				var td4=document.createElement("td");
				tr4.appendChild(td4);
				var name=document.createElement("div");
				name.setAttribute("style","margin-top:10px;");
				name.innerHTML="<h2 style='font-style:default;'>方案"+indexx+"：&nbsp;&nbsp;"+v.labelName+"</h1>";
				td4.appendChild(name);
				table.appendChild(tr4);
				table.appendChild(tr);
				table.appendChild(tr2);
				table.appendChild(tr3);
				table.appendChild(tr1);
				var td4=document.createElement("td");
				tr1.appendChild(td4);
				td4.innerHTML="<a style='cursor:pointer;' href='javascript:updateProject("+v.labelId+","+v.isReView+");'>修改</a>&nbsp;&nbsp;&nbsp;<a style='cursor:pointer;' href='javascript:deleteProject("+v.labelId+","+v.isReView+");'>删除</a>";
				var td1=document.createElement("td");
				td1.setAttribute("style", "vertical-align:middle;");
				var td2=document.createElement("td");
				td1.innerHTML="<img style='width:600px;height:auto' src='"+v.previewPicture+"'>";
				td2.setAttribute("height", "20px");
				var td3=document.createElement("td");
				td3.setAttribute("style", "vertical-align:middle;font-size:14px;color:#333;");
				td3.setAttribute("align", "left");
				tr.appendChild(td1);
				tr2.appendChild(td2);
				tr3.appendChild(td3);
				var func=document.createElement("div");
				func.setAttribute("style","margin-top:10px;");
				func.innerHTML="<font style='font-weight:bold;'>产品功能：</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;<font style='line-height: 135%;'>"+v.labelfunction+"</font>";
				td3.appendChild(func);
				var mark=document.createElement("div");
				mark.setAttribute("style","margin-top:10px;");
				mark.innerHTML="<font style='font-weight:bold;'>市场前景：</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;<font style='line-height: 135%;'>"+v.marketobject+"</font>";
				td3.appendChild(mark);
				var beizhu=document.createElement("div");
				beizhu.setAttribute("style","margin-top:10px;");
				beizhu.innerHTML="<font style='font-weight:bold;'>备注信息：</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;<font style='line-height: 135%;'>"+v.other+"</font>";
				td3.appendChild(beizhu);
				var shenhe=document.createElement("div");
				shenhe.setAttribute("style","margin-top:10px;");
				shenhe.innerHTML="<font style='font-weight:bold;'>审核情况：</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;<font style='line-height: 135%;'>"+v.isReView_bak+"</font>";
				td3.appendChild(shenhe);
				indexx++;
			});
			$("#shoppingCar_subtitle font:eq(3)").html("("+data.size+"个)");
		});
		//$("#MyProjectTable").append("<input type='button' style='float:left;' onclick=$('#newProduct').dialog('open'); value='提交新的作品'/>");
		document.getElementById("myDesignTable").style.display="none";
		document.getElementById("myOrderTable").style.display="none";
		document.getElementById("MyProjectTable").style.display="";
		document.getElementById("shoppingCar_subtitle").style.display="";}
	});
}

function deleteProject(a,b){
	if(b==0){
		if(confirm("确定删除设计？")){
			$.getJSON("getAndSetLabel_deleLebel.action",{
				labelid:a
			},function(){
				//alert("删除成功");
				$.weeboxs.open('删除成功', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
				setTimeout(showMyProject(),1000);
			});
		}
	}else{
		$.weeboxs.open('该设计已经审核，不能删除', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

function updateProject(a,b){
	if(b==0){
		$.getJSON("getAndSetLabel_getLebel.action",{
			labelid:a
		},function(data){
			$("#ProjectEdit Img:eq(0)").attr("src",data.label.previewPicture);
			$("#projectEdit Input:eq(0)").attr("value",data.label.labelName);
			$("#projectEdit Input:eq(1)").attr("value",data.label.labelfunction);
			$("#projectEdit Input:eq(2)").attr("value",data.label.marketobject);
			$("#projectEdit Input:eq(3)").attr("value",data.label.other);
			$("#projectEdit Input:eq(4)").attr("value",a);
			$("#projectEdit").dialog("open");
		});
	}else{
		//alert("该设计已经审核，不能修改。");
		$.weeboxs.open('该设计已经审核，不能删除', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

function editProject(){
	$.getJSON("getAndSetLabel_setLebel.action",{
		labelName:$("#projectEdit input:eq(0)").val(),
		labelfunction:$("#projectEdit input:eq(1)").val(),
		marketobject:$("#projectEdit input:eq(2)").val(),
		other:$("#projectEdit input:eq(3)").val(),
		labelid:$("#projectEdit input:eq(4)").val()
	},function(){
		//alert("修改成功");
		$.weeboxs.open('修改成功', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		$("#projectEdit").dialog("close");
		setTimeout(showMyProject(),1000);
	});

}
function showMyOrder(){
	if(document.getElementById("hiddenflag").value==0){
		document.getElementById("hiddenflag").value=1;
		$.getJSON("ShowMyOrder.action",function(data){
			var orderTable=document.getElementById("myOrderTable");
			$.each(data.ordersList,function(index,value){
				var div_all=document.createElement("div");
				div_all.setAttribute("style", "font-family: '微软雅黑';padding-top: 10px; overflow: hidden; width: 600px; clear: both; opacity: 1;");
				var table=document.createElement("table");
				table.setAttribute("style", "float:left;");
				var tr=document.createElement("tr");
				var td1=document.createElement("td");
				td1.setAttribute("style", "vertical-align:middle;");
				var td2=document.createElement("td");
				td2.setAttribute("width", "5%");
				var td3=document.createElement("td");
				td3.setAttribute("style", "vertical-align:middle;font-size:14px;color:#333;");
				td3.setAttribute("align", "left");
				td1.innerHTML="<img style='width:200px;height:auto' src='"+value.orderPic+"'>";

				var d1=document.createElement("div");
				d1.innerHTML="主题："+value.orderTheme;
				td3.appendChild(d1);
				var d2=document.createElement("div");
				d2.innerHTML="编号："+value.orderId;
				td3.appendChild(d2);
				var d3=document.createElement("div");
				d3.innerHTML="价格："+value.orderTotalPrice;
				td3.appendChild(d3);
				var d4=document.createElement("div");
				d4.innerHTML="数量："+value.orderProductsCount;
				td3.appendChild(d4);
				var d5=document.createElement("div");
				d5.innerHTML="户名："+value.orderName;
				td3.appendChild(d5);
				var d6=document.createElement("div");
				d6.innerHTML="电话："+value.orderMobilePhone;
				td3.appendChild(d6);
				var d7=document.createElement("div");
				d7.innerHTML="地址："+value.orderAddress;
				td3.appendChild(d7);
				td3.appendChild(document.createElement("br"));
				var d8=document.createElement("div");
				d8.innerHTML="设计时间："+value.orderTime_bak;
				td3.appendChild(d8);
				var d9=document.createElement("div");
				d9.innerHTML="物流信息："+value.orderFreight;
				td3.appendChild(d9);
				var d10=document.createElement("div");
				d10.innerHTML="备注："+value.orderContent;
				td3.appendChild(d10);
				var d11=document.createElement("div");

				if(value.orderState==0){
					var b1=document.createElement("input");
					b1.setAttribute("type", "button");
					b1.setAttribute("value", "去付款");
					b1.setAttribute("style", "border:0;background-color:#94b8e9;");
					b1.setAttribute("onclick", "goShop("+value.orderId+")");
					d11.appendChild(b1);
					var f1=document.createElement("font");
					f1.setAttribute("style", "color:white;visibility:hidden");
					f1.appendChild(document.createTextNode("00000000"));
					d11.appendChild(f1);
				}
				if(value.orderState==1){
					var b2=document.createElement("input");
					b2.setAttribute("type", "button");
					b2.setAttribute("value", "已付款");
					b2.setAttribute("style", "border:0;background-color:#94b8e9;");
					b2.setAttribute("disabled", "disabled");
					d11.appendChild(b2);
				}
				if(value.orderState==2){
					var b3=document.createElement("input");
					b3.setAttribute("type", "button");
					b3.setAttribute("value", "确认收货");
					b3.setAttribute("style", "border:0;background-color:#94b8e9;");
					b3.setAttribute("onclick", "$.weeboxs.open('请登录alipay.com确认收货', {title:'提示',showCancel:false,okBtnName: '确定',}); ");
					d11.appendChild(b3);
				}
				if(value.orderState==3){
					var b4=document.createElement("input");
					b4.setAttribute("type", "button");
					b4.setAttribute("value", "交易成功");
					b4.setAttribute("style", "border:0;background-color:#94b8e9;");
					b4.setAttribute("disabled", "disabled");
					d11.appendChild(b4);
				}
				if(value.orderState!=0){
					d11.appendChild(document.createTextNode(" "));
					var b5=document.createElement("input");
					b5.setAttribute("type", "button");
					b5.setAttribute("value", "再购买");
					b5.setAttribute("style", "border:0;background-color:#94b8e9;");
					b5.setAttribute("onclick", "repayment("+value.orderId+")");
					d11.appendChild(b5);
				}
				var f2=document.createElement("font");
				f2.setAttribute("style", "color:white;visibility:hidden");
				f2.appendChild(document.createTextNode("00000000"));
				d11.appendChild(f2);
				if(value.isShare==0){
					var b6=document.createElement("input");
					b6.setAttribute("type", "button");
					b6.setAttribute("value", "去分享");
					b6.setAttribute("style", "border:0;background-color:#94b8e9;");
					b6.setAttribute("onclick", "gotoParticipate("+value.orderId+",'o')");
					d11.appendChild(b6);
				}
				if(value.isShare==1){
					var b7=document.createElement("input");
					b7.setAttribute("type", "button");
					b7.setAttribute("value", "编辑分享");
					b7.setAttribute("style", "border:0;background-color:#94b8e9;");
					b7.setAttribute("onclick", "gotoParticipate("+value.orderId+",'o')");
					d11.appendChild(b7);
				}
				td3.appendChild(d11);

				tr.appendChild(td1);
				tr.appendChild(td2);
				tr.appendChild(td3);
				table.appendChild(tr);
				div_all.appendChild(table);
				orderTable.appendChild(div_all);
			});
		});

	}
	document.getElementById("myDesignTable").style.display="none";
	document.getElementById("myOrderTable").style.display="";
	document.getElementById("MyProjectTable").style.display="none";
	document.getElementById("shoppingCar_subtitle").style.display="";
}
function repayment(id){
	window.location.href="changeOrderToCustom.action?ordersId="+id;
}
function checkAll(){
	var obj = document.getElementById("checkAllbox");
	var cb1=document.getElementsByName("checkbox_payment");
	if(obj.checked){
		for(var i=0;i<cb1.length;i++){
			cb1[i].checked=true;
		}
	}else{
		for(var i=0;i<cb1.length;i++){
			cb1[i].checked=false;
		}
	}
}
function deleCustom(id){
	window.location.href="deleCustom.action?customId="+id;
}
function showCustom(id){
	window.location.href="showProduct.action?customId="+id;
}
function payment(){
	var flag=0;
	var a=document.getElementsByName("checkbox_payment");
	var a2="";
	for(var i=0;i<a.length;i++){
		if(a[i].checked){
			flag=1;
			a2=a2+a[i].value+",";
		}
	}
	if(flag==1){
		$.getJSON("chenkPayCondition.action",{
			customId:a2
		},function(data){
			if(data.f==0){
				//alert("您选择的订单收件地址或者收件人不同，不能同时支付，请分开支付。");
				$.weeboxs.open('您选择的订单收件地址或者收件人不同，不能同时支付，请分开支付。', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
			}else{
				window.location.href="showShoppingCar.action?customId="+a2+"&f=0";
			}
		});
	}else{
		alert("请先选中将要付款的设计。");
		return;
	}
}
function checkNumber(){
	var number=document.getElementById("buynumber").value;
	if(!(/^\d{1,}$/.test(number))){
		document.getElementById("buynumber").value="1";
		//alert("请输入数字!");
		$.weeboxs.open('请输入数字', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}
function goShop(id){
	window.location.href="showShoppingCar.action?ordersId="+id+"&f=1";
}
function toNewCustom(){
	window.location.href="showProduct.action";
}
function gotoShare(id){
	window.location.href="Sharepageedit.action?_id="+id;
}
function searchMyRecoFriends(){
	var value=$("#searchinputtext").val();
	if(value==null||value==''){
		//alert("请输入要查询的车主品牌或车主姓名！");
		$.weeboxs.open('请输入要查询的车主品牌或车主姓名！', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}else{
		$.getJSON("searchRecoFriends.action",{
			"value":value
		},function(data){
			$("#child4").empty();
			var hd=document.getElementById("child4");
			$.each(data.userhots,function(index,value){
				var div_img=document.createElement("div");
				div_img.setAttribute("class","my_order_mydesign_hisfriendinfo_child_username_img");
				var a_img=document.createElement("a");
				a_img.setAttribute("href","getFriendOwnMessageAction?uname="+value.userName);
				a_img.innerHTML="<img src='"+value.userFace+"' height='45px' width='45px'/>";
				div_img.appendChild(a_img);
				var div_detail=document.createElement("div");
				div_detail.setAttribute("class","my_order_mydesign_hisfriendinfo_child_username_detail");
				var div_name=document.createElement("div");
				div_name.setAttribute("class","my_order_mydesign_hisfriendinfo_child_username_detail_name");
				var div_username=document.createElement("div");
				div_username.setAttribute("class","friend_child_name");
				div_username.setAttribute("id","username");

				//var text_username=document.createTextNode(value.userName);
				//div_username.appendChild(text_username);
				var a_username=document.createElement("a");
				a_username.setAttribute("href", "getFriendOwnMessageAction?uname="+value.userName);
				a_username.innerHTML=value.userName;
				div_username.appendChild(a_username);
				div_name.appendChild(div_username);
				div_detail.appendChild(div_name);

				var div_zhishu=document.createElement("div");
				div_zhishu.setAttribute("class", "my_order_mydesign_hisfriendinfo_child_username_detail_renqi");
				div_zhishu.innerHTML="指数：("+value.usersHot+")";
				div_detail.appendChild(div_zhishu);

				hd.appendChild(div_img);
				hd.appendChild(div_detail);
			});
		},"json");
	}
}
var labelpass=false;
function checkName(){
	$.getJSON("checkLabelName.action",{
		labelname:$("#labelname").val()
	},function(data){
		if(data.result!=0){
			//alert("产品名称已存在！");
			$.weeboxs.open('产品已经存在', {
				title:'提示',
				timeout:5,
				showCancel:false,
				okBtnName: '确定',
			});
			labelpass=false;
		}else{
			labelpass=true;
		}
	});
}

function newProduct(){
	if(labelpass==true&&$.trim($("#function").val())!=''&&$.trim($("#market").val())!=''){
		document.getElementById("form1").submit();
		$("#shangchuanMsg").dialog("open");
		$("#newProduct").dialog('close');
		setTimeout(function(){
			$("#shangchuanMsg").dialog("close");
			showMyProject();
		},5000);
	}else{
		//alert("填写不完整！");
		$.weeboxs.open('填写不完整!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}
function gotoParticipate(id,type){
	window.location.href="showParticipateEdit.action?id="+id+"&type="+type;
}



